import axios from 'axios'
// import { Message, Loading } from 'element-ui'
import store from '@/store'
// import router from '@/router'
// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 50000 // 请求超时时间
})

// 设置token有效时长
// const time = 24 * 60 * 60 * 1000 // 有效时长1天
// let loading
// 请求拦截器
service.interceptors.request.use(config => {
  const token = store.state.user.token
  if (token) {
    config.headers.Authorization = 'Bearer ' + token
  }
  return config // 放行
})

service.interceptors.response.use()

export default service
